<?php 
class ListAdmin extends Module{
	function ListAdmin($row){
		Module::Module($row);
		
		if(User::is_admin()){
			switch(Url::get('cmd')){				
				case 'delete':
					$id=(int)Url::get('id',0);
					if($id){											
						DB::query('UPDATE user SET gids="0" WHERE id='.$id);
						User::getUser($id,1,true);
					}
					Url::redirect_url(Url::build_all(array('cmd','group_id','id')));
					break;
				
				case 'remove':											
					$id			=(int)Url::get('id',0);	
					$group_id	=(int)Url::get('group_id',0);	
					if($id)
					{
						if ($id != 1 || $group_id != 9)
						{
							$user = User::getUser($id);
							
							if($user&&$user!='0'){
								$gids='';
								
								$groups=User::get_groups($user['gids']);
								if($groups){
									foreach ($groups as $gid=>$group){
										if($group_id!=$gid){
											$gids.=($gids?'|':'').$gid;
										}
									}
								}
								if($gids=='')$gids='0';
								
								DB::query('UPDATE user SET gids="'.$gids.'" WHERE id='.$id);
							}
							
							User::getUser($id,0,1);
						}
					}
					Url::redirect_url(Url::build_all(array('cmd','group_id','id')));
					break;
				case 'remove_permit':											
					$pid			=(int)Url::get('pid',0);	
					$group_id		=(int)Url::get('group_id',0);	
					if($pid && $group_id && isset(CGlobal::$group[$group_id])){
						$permit=DB::select('user_permit','type=0 AND ref_id='.$group_id);
						if($permit){
							$pids='';
							$pid_arr=explode('|',$permit['pids']);
							if($pid_arr){
								foreach ($pid_arr as $id){
									if($id && $id!=$pid){
										$pids.=($pids?'|':'').$id;
									}
								}
							}
							
							$permit=array(
										'id'	=>$permit['id'],
										'type'	=>0,
										'ref_id'=>$group_id,
										'pids'	=>$pids,
										'cids'	=>''
										);
					
							DB::insert('user_permit',$permit,true);
						}
						
					}
					Url::redirect_current();
					break;
				
				default:
					require_once 'forms/ListAdmin.php';
					$this->add_form(new ListAdminForm());
					break;
			}			
		}
		else{
			Url::access_denied();
		}
	}
}
?>